package com.wm.task.view;

import java.util.Scanner;

public abstract class BaseView {
    protected Scanner sc = new Scanner(System.in);

    public void show() {
        while (true) {
            printMenu();
            String choice = getChoice();
            if (choice.equals("0")) {
                handleQuit();
                break;
            }
            handleChoice(choice);
            sc.nextLine();
        }
    }


    protected abstract void handleChoice(String choice);//处理选择

    protected void handleQuit() {
    }

    protected String getChoice() {
        System.out.print("请输入选择：");
        String choice = sc.nextLine();
        return choice;
    }

    protected abstract String getTitle();//获取标题

    protected abstract String[] getMenus();//获取菜单选项

    protected void printMenu() {
        System.out.println("===" + getTitle() + "===");
        String[] menus = getMenus();
        for (int i = 0; i < menus.length - 1; i++) {
            System.out.printf("%d、%s\n", i + 1, menus[i]);
        }
        System.out.println("0、" + menus[menus.length - 1]);
    }
}